<?php
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 2017/2/21
 * Time: 17:02
 */

namespace Admin\Controller;


use Common\Controller\AdminController;
use Common\Model\TypeAttrModel;

class TypeAttrController extends AdminController
{
    //属性列表
    public function lists()
    {
        $id =I('get.tid');
        $typeAttrData = m('type_attr')->where("tid = $id")->select();
        $this->assign('typeAttrData',$typeAttrData);
        $this->display();
    }

    //添加
    public function add()
    {
        $id = I('get.aid');
        if (IS_POST) {
//            print_r($_POST);
            $data = I('post.');
//            dump($data);die;
            if($id){
                $data['aid'] =$id;
            }
//            dump($data);
            $this->store(new TypeAttrModel(), $data, function () {
                $this->success('操作成功', u("TypeAttr/lists",['tid'=> I('post.tid')]));
                die;
            });
        }
        //分配旧数据
        if($id){
            $oldData = m('type_attr')->find($id);
        }else{
            $oldData =[];
        }
        $this->assign('oldData', $oldData);
        $this->display();
    }

    public function delAttr(){
        $id =I('get.aid');
//        dump($tid);die;
        $model = new TypeAttrModel();
        if($model->where("aid='{$id}'")->delete()){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

}